<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="发票抬头
" prop="takName">
        <el-input
          v-model="queryParams.takName"
          placeholder="请输入发票抬头
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司税号" prop="taxNumber">
        <el-input
          v-model="queryParams.taxNumber"
          placeholder="请输入公司税号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:tax:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:tax:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:tax:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:tax:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="taxList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="创建时间" align="center" prop="createdAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="发票抬头
" align="center" prop="takName" />
      <el-table-column label="公司税号" align="center" prop="taxNumber" />
      <el-table-column label="详细地址" align="center" prop="address" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="开户银行" align="center" prop="bank" />
      <el-table-column label="银行账号" align="center" prop="bankNumber" />
      <el-table-column label="邮箱" align="center" prop="userEmail" />
      <el-table-column label="创建用户昵称" align="center" prop="userName" />
      <!--<el-table-column label="创建模板用户类型 0 个人 1公司" align="center" prop="userType" />-->
      <el-table-column label="订单编号" align="center" prop="orderNo" />
      <el-table-column label="开发票状态" align="center" prop="status" >
        <template slot-scope="scope">
          <span v-if="scope.row.status ==0" >待处理</span>
          <span v-if="scope.row.status ==1">完成</span>
        </template>
      </el-table-column>
      <el-table-column label="充值金额" align="center" prop="amount" />
      <!--<el-table-column label="公司id" align="center" prop="companyId" />-->
      <el-table-column label="开票类型" align="center" prop="takType" >
        <template slot-scope="scope">
          <span v-if="scope.row.takType ==0" >个人</span>
          <span v-if="scope.row.takType ==1">企业</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:tax:edit']"
          >查看</el-button>
          <el-button
            v-if="scope.row.status ==0"
            style="width: 55px"
            size="mini"
            type="success"
            @click="complete(scope.row)"
          >完成</el-button>
         <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:tax:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改发票管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="发票抬头
" prop="takName">
          <span>{{form.takName || ''}}</span>
          <!--<el-input v-model="form.takName" placeholder="请输入发票抬头" />-->
        </el-form-item>
        <el-form-item label="公司税号" prop="taxNumber">
          <span>{{form.taxNumber || ''}}</span>
          <!--<el-input v-model="form.taxNumber" placeholder="请输入公司税号" />-->
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <span>{{form.address || ''}}</span>

         <!-- <el-input v-model="form.address" placeholder="请输入详细地址" />-->
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <span>{{form.mobile || ''}}</span>

         <!-- <el-input v-model="form.mobile" placeholder="请输入手机号" />-->
        </el-form-item>
        <el-form-item label="开户银行" prop="bank">
          <span>{{form.bank || ''}}</span>

       <!--   <el-input v-model="form.bank" placeholder="请输入开户银行" />-->
        </el-form-item>
        <el-form-item label="银行账号" prop="bankNumber">
          <span>{{form.bankNumber || ''}}</span>

         <!-- <el-input v-model="form.bankNumber" placeholder="请输入银行账号" />-->
        </el-form-item>
        <el-form-item label="邮箱" prop="userEmail">
          <span>{{form.userEmail || ''}}</span>

         <!-- <el-input v-model="form.userEmail" placeholder="请输入邮箱" />-->
        </el-form-item>
        <el-form-item label="创建用户昵称" prop="userName">
          <span>{{form.userName || ''}}</span>

         <!-- <el-input v-model="form.userId" placeholder="请输入创建用户id" />-->
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNo">
          <span>{{form.orderNo || ''}}</span>

         <!-- <el-input v-model="form.orderNo" placeholder="请输入订单编号" />-->
        </el-form-item>
        <el-form-item label="订单金额" prop="amount">
          <span>{{form.amount || ''}}</span>

         <!-- <el-input v-model="form.amount" placeholder="请输入充值金额" />-->
        </el-form-item>
       <!-- <el-form-item label="公司id" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入公司id" />
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
       <!-- <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTax, getTax, delTax, addTax, updateTax,complete } from "@/api/system/tax";

export default {
  name: "Tax",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 发票管理表格数据
      taxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: "id",
        createdAt: null,
        updatedAt: null,
        takName: null,
        taxNumber: null,
        address: null,
        mobile: null,
        bank: null,
        bankNumber: null,
        userEmail: null,
        userId: null,
        userType: null,
        orderNo: null,
        status: null,
        amount: null,
        companyId: null,
        takType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        amount: [
          { required: true, message: "充值金额不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    complete(item){
      console.log(item)
      this.$modal.confirm('是否完成当前订单的开票申请？').then(function() {
        return complete(item);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    /** 查询发票管理列表 */
    getList() {
      this.loading = true;
      listTax(this.queryParams).then(response => {
        this.taxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createdAt: null,
        updatedAt: null,
        takName: null,
        taxNumber: null,
        address: null,
        mobile: null,
        bank: null,
        bankNumber: null,
        userEmail: null,
        userId: null,
        userType: null,
        orderNo: null,
        status: null,
        amount: null,
        companyId: null,
        takType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加发票管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTax(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改发票管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTax(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTax(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除发票管理编号为"' + ids + '"的数据项？').then(function() {
        return delTax(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/tax/export', {
        ...this.queryParams
      }, `tax_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
